// debounce.js v-debounce 自己写防抖函数
function debounce(fn, wait) {
    let timer = null
    return function(...args) {
        let self = this
        if (timer) {
            clearInterval(timer)
            timer = null
        }
        timer = setTimeout(() => {
            return fn.apply(self, args)
        }, wait)
    }
}
export default {
    mounted(el, binding) {
        if (typeof binding.value !== 'function') {
            console.error('callback must be a function')
            return
        }
        el.__handleClick__ = debounce(binding.value, 300)
        el.addEventListener('click', el.__handleClick__)
    },
    beforeUnmount(el) {
        el.removeEventListener('click', el.__handleClick__)
    }
}
